package binary_tree.Heap;

import java.util.concurrent.ThreadLocalRandom;

/**
 * @Description: 测试最大堆
 * @Author Stark
 * @Date 2022/3/5 16:49
 **/
public class MaxHeapTest {
    public static void main(String[] args) {
//        int[] data = {15,17,19,13,22,16,28,30,41,62};
//        MaxHeap heap = new MaxHeap(data);
//        System.out.println(heap);
        int[] data = new int[100000];
        // 生成随机数
        ThreadLocalRandom random = ThreadLocalRandom.current();
        for (int i = 0; i < data.length; i++) {
           data[i] = random.nextInt(0,Integer.MAX_VALUE);
        }
        MaxHeap heap = new MaxHeap();
        for (int i : data) {
            heap.add(i);
        }
        for (int i = 0; i < data.length; i++) {
            data[i] = heap.extractMax();
        }
        System.out.println(isSorted(data));
    }

    public static boolean isSorted(int[] arr) {
        for (int i = 0; i < arr.length - 1; i++) {
            if (arr[i] < arr[i + 1]) {
                System.err.println("error");
                return false;
            }
        }
        return true;
    }
}
